<?php

namespace app\admin\model\order;

use think\Model;
use traits\model\SoftDelete;

class Rescue extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'rescue_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'distribution_status_text',
        'distributiontime_text',
        'take_status_text',
        'taketime_text',
        'reach_status_text',
        'reachtime_text',
        'order_status_text',
        'pay_status_text',
        'pay_way_text',
        'paytime_text'
    ];
    

    
    public function getDistributionStatusList()
    {
        return ['10' => __('Distribution_status 10'), '20' => __('Distribution_status 20')];
    }

    public function getTakeStatusList()
    {
        return ['10' => __('Take_status 10'), '20' => __('Take_status 20')];
    }

    public function getReachStatusList()
    {
        return ['10' => __('Reach_status 10'), '20' => __('Reach_status 20')];
    }

    public function getOrderStatusList()
    {
        return ['10' => __('Order_status 10'), '20' => __('Order_status 20'), '30' => __('Order_status 30')];
    }

    public function getPayStatusList()
    {
        return ['10' => __('Pay_status 10'), '20' => __('Pay_status 20')];
    }

    public function getPayWayList()
    {
        return ['10' => __('Pay_way 10'), '20' => __('Pay_way 20'), '30' => __('Pay_way 30')];
    }


    public function getDistributionStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['distribution_status']) ? $data['distribution_status'] : '');
        $list = $this->getDistributionStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDistributiontimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['distributiontime']) ? $data['distributiontime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTakeStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['take_status']) ? $data['take_status'] : '');
        $list = $this->getTakeStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTaketimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['taketime']) ? $data['taketime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReachStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reach_status']) ? $data['reach_status'] : '');
        $list = $this->getReachStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getReachtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reachtime']) ? $data['reachtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_status']) ? $data['pay_status'] : '');
        $list = $this->getPayStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayWayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_way']) ? $data['pay_way'] : '');
        $list = $this->getPayWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setDistributiontimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setTaketimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReachtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
